/*
 * Created on 29/06/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.ufmg.dees.insane.ui.rich.learn.learn_view.displacements_view;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JToolBar;
import javax.swing.text.Position;

import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.FrameDisplacementsController;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.GridFrameDisplacementsController;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdButton;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdMenu;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.DrawingArea;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.IView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnInterface;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnViewState;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.Command;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SelectCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.displacements_view.command.GetMatricialShapeCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.displacements_view.command.GetUCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.displacements_view.command.Help1Command;

/**
 * @author Renata Nicoliello
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class FrameDisplacementsView extends LearnView {  
	
//  No da arvore: Displacements
	private Command matricialShapeCmd = new GetMatricialShapeCommand(parent);
	private Command graficalShapeCmd = new GetUCommand(parent);
	private Command help1Cmd = new Help1Command(parent);
	
//	No Displacements
    private CmdMenu itemMatricialShape = new CmdMenu("Matricial Shape", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Form.gif")));
    private CmdMenu itemGraficalShape = new CmdMenu("Get U", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/FormElement.gif")));
    private CmdMenu itemHelp1 = new CmdMenu("Help", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));

    
    //No Displacements
    private CmdButton matricialShape = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Form.gif")));
    private CmdButton graficalShape = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/FormElement.gif")));
   private CmdButton help1 = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));
   
    private JMenu menuDisplacements = new JMenu("Displacements");
    private JToolBar displacementsToolBar = new JToolBar();
    
	public FrameDisplacementsView(LearnInterface parent, FemModel m){
	    super(parent,m);
		super.setViewState(new LearnViewState());
		super.setDrawingArea(new DrawingArea((IView)this));
		super.setController(new FrameDisplacementsController(this));
		
		
		String gAnlType = m.getGlobalAnalysisModel().getType();
		
		if (!(gAnlType.equals("Grid"))) {
			super.setController(new FrameDisplacementsController(this));
		} else {
			super.setController(new GridFrameDisplacementsController(this));
		}
		
		//Setting menu Displacements
		menuDisplacements.add(itemMatricialShape);
		itemMatricialShape.setCommand(matricialShapeCmd);
		itemMatricialShape.setEnabled(false);
		itemMatricialShape.setMnemonic(KeyEvent.VK_M);
		itemMatricialShape.addActionListener(parent);
        
		menuDisplacements.add(itemGraficalShape);
		itemGraficalShape.setCommand(graficalShapeCmd);
		itemGraficalShape.setEnabled(false);
		itemGraficalShape.setMnemonic(KeyEvent.VK_G);
		itemGraficalShape.addActionListener(parent);
		
		menuDisplacements.add(itemHelp1);
        itemHelp1.setCommand(help1Cmd);
        itemHelp1.setEnabled(false);
        itemHelp1.setMnemonic(KeyEvent.VK_H);
        itemHelp1.addActionListener(parent);
        
        displacementsToolBar.add(matricialShape);
        matricialShape.setToolTipText("Matricial Shape");
        matricialShape.addActionListener(parent);
        matricialShape.setCommand(matricialShapeCmd);
        
        displacementsToolBar.add(graficalShape);
        graficalShape.setToolTipText("Get U");
        graficalShape.addActionListener(parent);
        graficalShape.setCommand(graficalShapeCmd);
        
       
        displacementsToolBar.add(help1);
		help1.setToolTipText("Help");
		help1.addActionListener(parent);
		help1.setCommand(help1Cmd);
        
	}
	
	public void init(){
	    super.init();
			parent.getMenuPanel().removeAll();
			parent.getMenuPanel().add(menuFile);
			itemSave.setEnabled(true);
			itemSaveAs.setEnabled(true);
			itemClose.setEnabled(true);
			itemPrint.setEnabled(true);
			menuExport.setEnabled(true);
			menuImport.setEnabled(true);
			parent.getMenuPanel().add(menuEdit);
			parent.getMenuPanel().add(menuView);
			parent.getMenuPanel().add(menuDisplacements);
			menuDisplacements.setEnabled(true);
			itemMatricialShape.setEnabled(true);
			itemGraficalShape.setEnabled(true);
			itemHelp1.setEnabled(true);
			parent.getMenuPanel().add(menuSettings);
			parent.getMenuPanel().add(menuHelp);
	        
			parent.getToolPanel().removeAll();
			parent.getToolPanel().add(fileToolBar);
			save.setEnabled(true);
			saveAs.setEnabled(true);
			print.setEnabled(true);
			delete.setEnabled(false);
			parent.getToolPanel().add(editToolBar);
			parent.getToolPanel().add(zoomToolBar);
			parent.getToolPanel().add(displacementsToolBar);
			matricialShape.setEnabled(true);
			graficalShape.setEnabled(true);
			help1.setEnabled(true);
							
	        parent.getConsolePanel().setVisible(true);
			
			grid.setEnabled(true);
			snap.setEnabled(true);
			
			this.getDrawingArea().setRepainting(false);
			this.getDrawingArea().repaint();
	        
			parent.getConsoleHandler().setToCommandMode();
			parent.getConsoleHandler().setKeybCommand(null);
			
			this.setStateButtons();
			
			parent.getTree().setEnabled(true);
			parent.getTree().setSelectionPath(parent.getTree().getNextMatch("Displacements", 0, Position.Bias.Forward));
			
			this.getController().compose();

			parent.getDrawPanel().removeAll();
			parent.getDrawPanel().add(this.getDrawingArea(), BorderLayout.CENTER);
			this.getDrawingArea().removeAllCommands();
			this.getDrawingArea().setClickedCommand(new SelectCommand(parent));
			this.getDrawingArea().setCursor();
			parent.getDrawPanel().repaint();
			parent.getDrawPanel().updateUI();
			
			parent.getJMenuBar().updateUI();
			parent.repaint();
	    }   

	public  JFrame getInterface(){
    	return parent;
    }
    
	public void setInterface(JFrame par){
    	this.parent = (LearnInterface)par;
    }

    public void setCoord(String x, String y){
    	this.parent.setCoord(x, y);
    }
    
    public void setMessage(String m){
    	this.parent.setMessage(m);
    }

}
